<template>
    <div>
        <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
            <el-menu-item index="1" style="width: 50%">基本信息</el-menu-item>
            <el-menu-item index="2" style="width: 50%">债权信息</el-menu-item>
        </el-menu>
        <div v-if="readyShow">
            <creditor-info v-show="creditorInfoVisible" :form="form"></creditor-info>
            <creditor-credit v-show="creditorCreditVisible" :creditinfoList="creditinfoList"></creditor-credit>
        </div>
    </div>
</template>

<script>
    import CreditorInfo from './components/creditor-info.vue'
    import CreditorCredit from './components/creditor-credit.vue'
    import util from 'assets/js/util.js'
    import conf from 'assets/js/conf.js'

    export default {
        data() {
            return {
                activeIndex: '1',
                creditorInfoVisible: true,
                creditorCreditVisible: false,
                creditinfoList: [],
                form: {
                    address: '',
                    orgName: '',
                    orgCode: '',
                    email: '',
                    idcard: '',
                    idcardFront: '',
                    idcardReverse: '',
                    mobile: '',
                    agentType: '',
                    bankCode: '',
                    bankName: '',
                    bankAccount: '',
                    caseId: '',
                    identityType: '',
                    mainObligor: '',
                    name: '',
                    idType: '',
                    id: '',
                    tel: '',
                    specialCreditor:'',
                    specialNote:'',
                    especiallyFileList:[],
                    agentDetailInfo: {
                        name: '',
                        idcardFront: '',
                        idcardReverse: '',
                        identityType:'',
                        idType: '',
                        idcard: '',
                        mobile: '',
                        email: '',
                        address: '',
                    }
                },
                readyShow: false,
            }
        },
        mounted: function () {

            const _self = this;
            util.ajax({
                url: `/creditor/detail`,
                params: {creditId: util.getUrlParam(document.location.href, 'id')},
                success: function (data) {
                    //代理人
                    if(data.data.agentDetailInfo !== ''){
                        _self.form.agentDetailInfo.idcardFront = conf.baseUrl + '/file/get/' + data.data.agentDetailInfo.idcardFront + '?type=1';
                        _self.form.agentDetailInfo.idcardReverse = conf.baseUrl + '/file/get/' + data.data.agentDetailInfo.idcardReverse + '?type=1';
                        _self.form.agentDetailInfo.mobile = data.data.agentDetailInfo.mobile;
                        _self.form.agentDetailInfo.email = data.data.agentDetailInfo.email;
                        _self.form.agentDetailInfo.idcard = data.data.agentDetailInfo.idcard;
                        _self.form.agentDetailInfo.address = data.data.agentDetailInfo.address;
                        _self.form.agentDetailInfo.name = data.data.agentDetailInfo.name;
                        _self.form.agentDetailInfo.identityType = _self.matchIdentityText(data.data.agentDetailInfo.identityType);
                        _self.form.agentDetailInfo.idType = _self.matchIdTypeText(data.data.agentDetailInfo.idType);
                        _self.agentDetailInfo = data.data.agentDetailInfo;

                    }

                    //本人
                    _self.form.address = data.data.address;
                    _self.form.orgName = data.data.orgName;
                    _self.form.orgCode = data.data.orgCode;
                    _self.form.email = data.data.email;
                    _self.form.idcard = data.data.idcard;
                    _self.form.idcardFront = conf.baseUrl + '/file/get/' + data.data.idcardFront + '?type=1';
                    _self.form.idcardReverse = conf.baseUrl + '/file/get/' + data.data.idcardReverse + '?type=1';
                    _self.form.idType = _self.matchIdTypeText(data.data.idType);
                    _self.form.bankAccount = data.data.bankAccount;
                    _self.form.bankUname = data.data.bankUname;
                    _self.form.bankName = data.data.bankName;
                    _self.form.state = data.data.state;
                    _self.form.checkedNote = data.data.checkedNote;
                    _self.form.agentType = _self.matchAgentTypeText(data.data.agentType);
                    _self.form.name = data.data.name;
                    _self.form.mobile = data.data.mobile;
                    _self.form.id = data.data.id;
                    _self.form.identityType = _self.matchNatureText(data.data.identityType);
                    _self.form.tel = data.data.tel;
                    //特别申报
                    _self.form.specialCreditor = data.data.specialCreditor;
                    _self.form.specialNote = data.data.specialNote;
                    _self.form.specialFileIds = data.data.specialFileIds;


                    util.ajax({
                        url: '/file/getFileList',
                        params: {eids:this.specialFileIds},
                        success: function (data) {
                            data.data.forEach(_file => _self.especiallyFileList.push({
                                name:'文件' + (data.data.specialFileIds),
                               id:_file.id,
                            }))
                        },
                    });



                    util.ajax({
                        url: `/credit/list`,
                        success: function (data) {
                            data.data.forEach(_credit => _self.creditinfoList.push({
                                time: util.formatDate(_credit.createDate) || '',
                                stateStr: _credit.stateStr,
                                creditNo: _credit.creditNo,
                                state: _credit.state,
                                id: _credit.id,
                            }));
                            _self.readyShow = true;
                        }
                    });
                },
            });

        },
        props: [
            'id'
        ],

        methods: {
            handleSelect: function (key, keyPath) {
                this.creditorInfoVisible = false;
                this.creditorCreditVisible = false;

                switch (key) {
                    case '1':
                        this.creditorInfoVisible = true;
                        break;
                    case '2':
                        this.creditorCreditVisible = true;
                        break;
                }
            },
            /*matchTypeText: function (type) {
                let typeText = '';
                switch (type) {
                    case 1:
                        typeText = '职工债权';
                        break;
                    case 2:
                        typeText = '普通债权';
                        break;
                    case 3:
                        typeText = '税收债权';
                        break;
                    case 4:
                        typeText = '优先债权';
                        break;
                    default:
                        break;
                }
                return typeText
            },*/
            matchIdentityText: function (typeText) {
                let type = '操作委托人';
                switch (typeText) {
                    case 1:
                        type = '操作委托人';
                        break;
                    case 2:
                        type = '律师委托人';
                        break;
                    case 3:
                        type = '公司负责人';
                        break;
                    default:
                        break;
                }
                return type;
            },
            matchAgentTypeText: function (type) {
                let text = 0;
                switch (type) {
                    case 0:
                        text = '本人';
                        break;
                    case 1:
                        text = '代理人';
                        break;
                    case 2:
                        text = '特别申报';
                        break;
                    default:
                        break
                }
                return text;
            },
            matchIdTypeText: function (type) {
                let text = 0;
                switch (type) {
                    case 1:
                        text = '身份证';
                        break;
                    case 2:
                        text = '执业证';
                        break;
                    case 3:
                        text = '护照';
                        break;
                    default:
                        break
                }
                return text;
            },
            matchNatureText: function (type) {
                let text = 0;
                switch (type) {
                    case 1:
                        text = '个人';
                        break;
                    case 2:
                        text = '公司（机构）';
                        break;
                    case 3:
                        text = '行政机关（金融机构）';
                        break;
                    default:
                        break
                }
                return text;
            },
        },
        components: {
            CreditorInfo,
            CreditorCredit
        }
    }
</script>

<style scoped>
    .el-menu li {
        text-align: center;
    }
</style>
